package com.easidea.tim.flex.remote.inventory
{
	import com.easidea.tim.flex.Env;
	import com.easidea.tim.flex.event.CustomerEvent;
	import com.easidea.tim.flex.remote.BaseDao;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.mxml.RemoteObject;
	
	public class StorageHistoryDao extends BaseDao
	{
		private var _service:RemoteObject = new RemoteObject();
		private static var _instance:StorageHistoryDao;
		
		public static function getInstance():StorageHistoryDao {
			if ( _instance == null ){
				_instance = new StorageHistoryDao();
			}
			return _instance;
		}
		
		function StorageHistoryDao()
		{
			_service.channelSet = this.buildChannelSet();
			_service.destination = "storageHistoryService";
			_service.concurrency = "last";
			_service.makeObjectsBindable = true;
			_service.showBusyCursor = true;
		}

		public function listStorageHistory (pName:String , colorCode:String, sampleFlag:Boolean, startDate:Date, endDate:Date):void {
			_service.addEventListener(FaultEvent.FAULT, _Fault);
			_service.addEventListener(ResultEvent.RESULT, listStorageHistoryProcess);
			_service.getStorageHistoryList(pName, colorCode, sampleFlag, startDate, endDate);
		}
		
		private function listStorageHistoryProcess(e:ResultEvent):void{
			_service.removeEventListener(ResultEvent.RESULT, listStorageHistoryProcess);
			Env.dispatchEvent(new CustomerEvent("listStorageHistorySuccesfully",e.result));
		}
	}
}